<?php
 
class PhpFox_Mod_Site_ComponentPageCreate extends BaseComponent
{
	function process()
	{
		$oSrvPage = &$this->_oModule->getService('Page');
		
		$oSrvMenu = &App::getModuleService('Menu', 'Menu');
		
		$oReq = &App::getRequest();
		
		$aPost = $oReq->getArray('var');
		
		if ( (!empty($aPost['title_head'])) AND (!empty($aPost['content'])) AND (empty($aPost['edit_id'])) )
		{
			if ( !$oSrvMenu->_checkUrl($aPost['title_url']) )
			{
				$aError[] = App::format('Mod_Site.title.in.use');
			}
			
			if ( !isset($aError) )
			{
				$iNewPageId = $oSrvPage->_add($aPost);
			}
		}
		
		if ( (!empty($aPost['edit_id'])) )
		{
			if ( $aPost['old_url'] != $aPost['title_url'] && !$oSrvMenu->_checkUrl($aPost['title_url']) )
			{
				$aError[] = App::format('Mod_Site.title.in.use');
			}
			
			if ( !isset($aError) )
			{
				$bIsPageEdit = $oSrvPage->_update($aPost, $aPost['edit_id']);
			}
		}
		
		if ( $iEditId = $oReq->get('id') )
		{
			$aEditContent = $oSrvPage->_edit($iEditId);
		}
		
		$this->oTpl->assign(array
		(
			'aError' => (isset($aError) ? $aError : ''),
			'bUseTinyMCE' => ($oReq->get('wysiwyg') ? true : false),
			'bIsPageEdit' => (isset($bIsPageEdit) ? $bIsPageEdit : ''),
			'aEdit' => (isset($aEditContent) ? $aEditContent : ''),
			'iNewPageId' => (isset($iNewPageId) ? $iNewPageId : ''),			
		));	
	
		return $this->oTpl->fetch('PageCreate.html');
	}
}

?>